package ru.autofan.secure;

import java.util.HashSet;
import java.util.Set;

import ru.autofan.domain.AuthRole;
import ru.autofan.domain.Role;

public class CurrentRolesHolder {

	public static ThreadLocal<Set<Role>> contextLoggedRoles = new ThreadLocal<Set<Role>>(); 
	
	public CurrentRolesHolder() {
	}
	
	private ThreadLocal<Set<Role>> getContext() {
		return contextLoggedRoles;
	}
	
	public Set<Role> getRoles() {
		return getContext().get();
	}

	public void setRoles(Set<Role> newRoles) {
		getContext().set(newRoles);
	}

	public void setRole(Role newRole) {
		Set<Role> set = new HashSet<Role>();
		// AuthRole role = new AuthRole("ANONYMOUS");
		set.add(newRole);
		contextLoggedRoles.set(set);
	}
	
}
